<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,Chrome=1">
    <!-- Google Chrome Frame也可以让IE用上Chrome的引擎: -->
    <meta name="renderer" content="webkit">
    <!--国产浏览器高速模式-->
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>作业管理系统</title>
    <!-- 公共样式 开始 -->
    <link rel="stylesheet" type="text/css" href="../../css/base.css">
    <link rel="stylesheet" type="text/css" href="../../css/iconfont.css">
    <script type="text/javascript" src="../../framework/jquery-1.11.3.min.js"></script>
    <link rel="stylesheet" type="text/css" href="../../layui/css/layui.css">
    <script type="text/javascript" src="../../layui/layui.js"></script>
    <!-- 滚动条插件 -->
    <link rel="stylesheet" type="text/css" href="../../css/jquery.mCustomScrollbar.css">
    <script src="../../framework/jquery-ui-1.10.4.min.js"></script>
    <script src="../../framework/jquery.mousewheel.min.js"></script>
    <script src="../../framework/jquery.mCustomScrollbar.min.js"></script>
    <script src="../../framework/cframe.js"></script><!-- 仅供所有子页面使用 -->
    <!-- 公共样式 结束 -->
    <script type="text/javascript" src="../../framework/frameAll.js"></script>
    <style>
        .layui-form {
            margin-right: 30%;
        }
    </style>
</head>

<body>
<div class="cBody">
    <form id="addForm" class="layui-form" lay-filter="infoForm">
        <div class="layui-form-item">
            <label class="layui-form-label">教师号 : </label>
            <div class="layui-input-inline shortInput">
                <input type="text" name="no" autocomplete="off" class="layui-input" readOnly="true">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">姓&emsp;名 : </label>
            <div class="layui-input-inline shortInput">
                <input type="text" name="name" autocomplete="off" class="layui-input"
                       placeholder="请输入您的姓名" lay-verify="name">
                <input type="hidden" name="defaultName">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">年&emsp;龄 : </label>
            <div class="layui-input-inline shortInput">
                <input type="text" name="age" autocomplete="off" class="layui-input"
                       placeholder="请输入您的年龄" lay-verify="age">
                <input type="hidden" name="defaultAge">
            </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">邮箱 : </label>
                <div class="layui-input-inline shortInput">
                    <input type="text" name="email" autocomplete="off" class="layui-input" lay-verify="email">
                    <input type="hidden" name="defaultEmail">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">电话号码 : </label>
                <div class="layui-input-inline shortInput">
                    <input type="text" name="phone" autocomplete="off" class="layui-input" lay-verify="phone">
                    <input type="hidden" name="defaultPhone">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">性&emsp;别 : </label>
                <div class="layui-input-block">
                    <input type="radio" name="sex" value="0" title="男">
                    <input type="radio" name="sex" value="1" title="女">
                    <input type="hidden" name="defaultSex">
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn layui-btn-radius" lay-submit lay-filter="submitBut">修&nbsp;&nbsp;&nbsp;&nbsp;改</button>
                    <button class="layui-btn layui-btn-primary" id="primary" type="button">重&nbsp;&nbsp;&nbsp;&nbsp;置</button>
                </div>
            </div>
    </form>
</div>
<script>
    layui.use('form', function () {
        var form = layui.form;
        //初始化
        function loadData() {
            $.ajax({
                type: "POST",
                url: "/UserServlet.do",
                data: {action: "getUser"},
                dataType: "Json",
                success: function (data) {
                    if (data.user) {
                        form.val('infoForm', {
                            no: data.user.no,
                            className: data.user.className,
                            name: data.user.name,
                            age: data.user.age,
                            email: data.user.email,
                            phone: data.user.phone,
                            sex: data.user.sex === "男" ? 0 : 1,
                        });
                    }
                },
                error: function () {
                    noMsg("数据获取失败！");
                }
            });
        }
        loadData();
        //监听提交
        form.on('submit(submitBut)', function (data) {
            var field = data.field;
            $.ajax({
                type: "post",
                url: "/UserServlet.do",
                data: {
                    action: "updeteInfo",
                    name: field.name,
                    age: field.age,
                    email: field.email,
                    phone: field.phone,
                    sex: field.sex
                },
                dataType: "text",
                success: function (data) {
                    if (data) {
                        var tip = parseInt(data);
                        if (tip == 0) {
                            yesMsg("修改成功");
                        } else {
                            $("#password").focus();
                            noMsg("修改失败");
                        }
                    }
                }
            });
            return false;
        });
        //重置监听
        $("#primary").click(function () {
            yesMsg("已重置");
            loadData();
        })
    });
</script>
</body>

</html>